/*
 * @Date: 2023-01-08 13:38:19
 * @LastEditors: Zireael 1193875164@qq.com
 * @LastEditTime: 2023-03-27 11:28:28
 * @FilePath: \A19\frontend\vite.config.ts
 */
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";

import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import ViteCompression from "vite-plugin-compression";

// https://vitejs.dev/config/
export default defineConfig({
  optimizeDeps: {
    include: [
      `monaco-editor/esm/vs/language/json/json.worker`,
      `monaco-editor/esm/vs/language/css/css.worker`,
      `monaco-editor/esm/vs/language/html/html.worker`,
      `monaco-editor/esm/vs/language/typescript/ts.worker`,
      `monaco-editor/esm/vs/editor/editor.worker`,
    ],
  },
  build:{
    minify:'terser',
    terserOptions:{
      compress:{
        drop_console:true,
        drop_debugger:true,
      }
    },
    rollupOptions:{
      output:{
        chunkFileNames:'static/js/[name]-[hash].js',
        entryFileNames:'static/js/[name]-[hash].js',
        assetFileNames:'static/[ext]/[name]-[hash].[ext]',
        manualChunks(id){
          if(id.includes('node_modules')){
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        }
      }
    }
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    ViteCompression({
      threshold: 10240,
      verbose:true,
      algorithm:'gzip',
    }),
  ],
  resolve: {
    // 配置路径别名
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
});
